﻿using Mimas.Core.Current;
using Mimas.Framework.Shared.Data.DataTransferObjects;
using Mimas.Framework.Shared.Data.EnumObjects;
using System;
using System.Linq;

namespace Mimas.Framework.Server.DomainObjects.Mapping
{
    public static class UserBanListMapping
    {
        public static UserBanList Map(UserBanListDTO data)
        {
            UserBanList newItem = new UserBanList();

            newItem.BanTypeId = (int)data.BanType;
            newItem.EndDate = data.EndDate;
            newItem.Id = data.Id;
            newItem.StartDate = data.StartDate;
            newItem.UserId = data.UserId;
            newItem.Explanation = data.Explanation;

            if (data.Id == 0)
            {
                newItem.CreatedBy = UserInfo.CurrentUser.UserId;
                newItem.CreatedOn = DateTime.Now;
            }
            else
            {
                newItem.ModifiedBy = UserInfo.CurrentUser.UserId;
                newItem.ModifiedOn = DateTime.Now;
            }

            return newItem;
        }

        public static UserBanListDTO Map(UserBanList data)
        {
            UserBanListDTO newItem = new UserBanListDTO();

            newItem.BanType = (EBanType)data.BanTypeId;
            newItem.EndDate = data.EndDate;
            newItem.Id = data.Id;
            newItem.StartDate = data.StartDate;
            newItem.UserId = data.UserId;
            newItem.Explanation = data.Explanation;

            return newItem;
        }

        public static UserBanList[] Map(UserBanListDTO[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }

        public static UserBanListDTO[] Map(UserBanList[] data)
        {
            if (data == null || !data.Any()) return null;
            return data.Where(x => x != null).Select(x => Map(x)).ToArray();
        }
    }
}
